﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Collections;
using Granite.Modeling;

namespace Scratch
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            //Resources.Add("Baz", Foo.Baz);
            //Resources["Baz"] = Foo.Baz;
            //App.Current.Resources["Baz"] = Foo.Baz;
            InitializeComponent();
            DataContext = new Foo() { Bar = 1 };
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            if (this.DynamicDataContext().Bar == 0)
                this.DynamicDataContext().Bar = 1;
            else
                this.DynamicDataContext().Bar = 0;
        }

    }

    public class Lights : Dictionary<int, string>
    {
        public Lights()
        {
            Add(0, "Off");
            Add(1, "On");
        }
    }

    public static class Extensions
    {
        public static dynamic DynamicDataContext(this FrameworkElement window)
        {
            return window.DataContext;
        }
    }

    public class Foo : SimpleModelBase
    {

        public int Bar
        {
            get { return Get<int>("Bar"); }
            set { Set(value, "Bar"); }
        }
    }
}
